class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int res = 0;
        int minNum = prices[0];
        for(int i = 1; i < prices.size(); i++)
        {
            minNum = std::min(minNum, prices[i]);
            res = std::max(res, prices[i]-minNum);
        }

        return res;
    }
};